﻿using iTextSharp.text;
using iTextSharp.text.pdf; 

namespace TianYu.Core.Pdf.Extension
{
    public static class PdfContentByteExtension
    {

        public static void WriteSolidLine(this PdfContentByte @this, float lineWidth, int x1, int y1, int x2, int y2)
        {
            @this.SetLineWidth(lineWidth);
            @this.MoveTo(x1, y1);
            @this.LineTo(x2, y2);
            @this.Stroke();
        }

        /// <summary>
        /// 画线
        /// </summary>
        /// <param name="this"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="x1"></param>
        /// <param name="y1"></param>
        /// <param name="lineStyle">线条类型</param>
        /// <param name="lineWidth"></param>
        public static void WriteSolidLine(this PdfContentByte @this, float x, float y, float x1, float y1, LineStyle lineStyle, float lineWidth)
        {
            @this.SetLineWidth(lineWidth / 1.5f);//细1.5倍是最接近后台设置的粗细
            @this.SetColorStroke(BaseColor.BLACK);
            @this.MoveTo(x, y);
            @this.LineTo(x1, y1);

            if (lineStyle == LineStyle.Dashed)
            {
                @this.SetLineDash(3, 3);
            }
            else if (lineStyle == LineStyle.Dotted)
            {
                @this.SetLineDash(1, 1);
            }

            @this.Stroke();
        }
    }
}
